<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const orders = [
        {
          id: 1,
          name: "John Smith",
          address: "123 Main St",
          status: "created",
          log: [
            {
              status: "created",
              time: "2023-02-16 12:30:00",
            },
          ],
        },
        {
          id: 2,
          name: "Jane Doe",
          address: "456 Second St",
          status: "packed",
          log: [
            {
              status: "created",
              time: "2023-02-16 10:00:00",
            },
            {
              status: "packed",
              time: "2023-02-16 12:30:00",
            },
          ],
        },
        {
          id: 3,
          name: "Bob Johnson",
          address: "789 Third St",
          status: "shipped",
          log: [
            {
              status: "created",
              time: "2023-02-15 10:00:00",
            },
            {
              status: "packed",
              time: "2023-02-15 12:00:00",
            },
            {
              status: "shipped",
              time: "2023-02-16 9:00:00",
            },
          ],
        },
      ];

      const getOrdersByStatus = (data) => {
        const arr = [];
        orders.forEach((item) => {
          // console.log(item);
          const { id, name, address, status, log } = item;
        //   if (status === data) {
            log.forEach((item) => {
              if (item.status === data) {
                // console.log(item);
                obj = {
                  id: id,
                  name: name,
                  address: address,
                  status: status,
                  log: item,
                };
                arr.push(obj);
              }
            });
        //   }
        });

        arr.sort((a,b) => a.id - b.id)

        console.log(arr);
      };

      getOrdersByStatus("packed");




      const getOrderStatusHistory = (data) =>{

        for(let i =0;i<orders.length;i++) {
          if(orders[i].id ===data){
            const rem = orders[i].log
           
            rem.sort((a,b) => new Date(a.time) < new Date(b.time) ? -1: 1)
            // const res = arr.join(' ')
            const arr =[]
            rem.forEach(item => arr.push([item.time],item.status))
            // rem.forEach(item => {
            //   const rem = Object.values(item)
            //   arr.push(rem)
            // })

            const res = arr.join('\n')
            return res
          }
        }
       
      }



      const ass= getOrderStatusHistory(3)
      console.log(ass);
    </script>
  </body>
</html>